****************************************************************************************************
* This is the code to replicate the results of the article "Political Leaders, Economic Hardship, and Foreign Aid Allocation"
* To be run on:
* - FPA-21-Sep-0168.dta
* Analyses of the article were done with Stata/MP 17.0 for Mac (Intel 64-bit)
***********************************************************************************************************************


cd ""


use "FPA-21-Sep-0168.dta", clear

**** INSTALL Making regression tables from stored ****
* net install st0085_2

xtset ccode year


**** TABLE 1 ****

global method "eststo: xtpcse"
global dv "ln_aid"
global fix "i.ccode i.year"
global iv "L.f_economic_hardship"
global int "L.log_rile cL.f_economic_hardship#cL.log_rile"
global cv "L.ln_gdppc L.wdi_gdpgr L.wdi_trade L.log_rile L.College L.studyabroad L.female L.age"

$method $dv $fix $iv , het
est store model1
$method $dv $fix $iv $cv , het

esttab, nogap comp se(3) b(3) keep($iv $cv _cons) ///
order($iv $cv _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear


**** TABLE 2 ****

$method ln_socialinfra $fix $iv , het
$method ln_socialinfra $fix $iv $cv , het
$method ln_economicinfra $fix $iv , het
$method ln_economicinfra $fix $iv $cv , het
$method ln_humanaid $fix $iv , het
$method ln_humanaid $fix $iv $cv , het

esttab, nogap comp se(3) b(3) keep($iv $cv _cons) ///
order($iv $cv _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear


**** FIGURE 1 ****

sort year

by year: egen m_hardship=mean(f_economic_hardship) if _est_model1==1
by year: egen m_affluent=mean(f_affluent) if _est_model1==1

label var m_hardship "Poor background"
label var m_affluent "Rich background"


twoway line m_hardship year if _est_model1==1 & year>=1975, || ///
	line m_affluent year if _est_model1==1 & year>=1975, clpattern(dash) ///
	graphregion(color(white))	/// get rid of the gray outerbox
	ylabel(0 "0" 0.1 "10" 0.2 "20" 0.3 "30" 0.4 "40" 0.5 "50", labsize(2.5) nogrid) ///
	xlabel(1980(10)2020, labsize(2.5) nogrid) ///
	ytitle(Distribution of material background (%),) xtitle("",) name(Figure1, replace)

xtset ccode year


**** FIGURE 2 ****

xtpcse $dv $fix $iv $int $cv2 , het
est store model2

margins, at(L.log_rile=(-3.5(0.1)3.9)) dydx(L.f_economic_hardship) noestimcheck
marginsplot,  ///
	 scheme(s2mono) 	/// 
	 ci1opts(recast(rline) lcolor(gs6) lwidth(thin) lpattern(dash)) /// 
	 plot1opt(lpattern(solid) lcolor(gs6) lwidth(thin)) ///
	 recast(line)  /// 
	 ylabel(-.5 "-0.5" 0 "0" .5 "0.5" 1 "1" , angle(0) nogrid)	/// 
	 xtitle("Leader's RILE")	/// 
	 ytitle("Marginal effect of economic hardship", size(3)) ///
	 title("Marginal effect of economic hardship on foreign aid", size(4))	/// 
	 xlabel(-4 "-4" -2 "-2" 0 "0" 2 "2" 4 "4", nogrid)	///
	 yline(0, lcolor(gs10) lpattern(--) lwidth(vthin)) ///
	 legend(off) ///
	 name(figure2a, replace)

margins, at(L.log_rile=(-3.5(0.1)3.9) L.f_economic_hardship=(0 1)) noestimcheck
marginsplot,  ///
	 scheme(s2mono) 	/// 
	 ci1opts(recast(rline)  lcolor(gs10) lwidth(thin) lpattern(dash)) /// 
	 plot1opt(lpattern(solid) lcolor(gs10) lwidth(thin)) ///
	 ci2opts(recast(rline) lcolor(gs6) lwidth(thin) lpattern(dash)) /// 
	 plot2opt(lpattern(solid) lcolor(gs6) lwidth(thin)) ///
	 recast(line)  /// 
	 ylabel(7.5(0.5)8.5, angle(0) nogrid)	/// 
	 xtitle("Leader's RILE")	/// 
	 ytitle("Predicted level of foreign aid (logged)", size(3)) /// 
	 title("Effect of economic hardship on foreign aid by leader's partisanship", size(4))	/// 
	 xlabel(-4 "-4" -2 "-2" 0 "0" 2 "2" 4 "4", nogrid)	///
	 legend(order(3 "Economic Hardship = 0" 4 "Economic Hardship = 1") size(3)) ///
	 name(figure2b, replace)

graph combine figure2a figure2b, scheme(s2mono) ysize(7) col(1) ///
note("95% confidence intervals", size(2)) name(figure2, replace)
	 


**** TABLE A3 ****

global method "eststo: xtpcse"
global dv "ln_aid"
global fix "i.ccode i.year"
global iv "L.f_economic_hardship"
global int "L.log_rile cL.f_economic_hardship#cL.log_rile"
global cv "L.ln_gdppc L.wdi_gdpgr L.wdi_trade L.log_rile L.College L.studyabroad L.female L.age"
global jobs "L.businessman L.lawyers L.blue_collar L.politician L.profescien L.civil_servant L.journalist"
global exp "L.expenditure"
global wel "L.totsp_ppp"

$method $dv $fix $iv $cv $jobs , het
$method $dv $fix $iv $cv $exp , het
$method $dv $fix $iv $cv $wel , het

esttab, nogap comp se(3) b(3) keep($iv $cv $jobs $exp $wel _cons) ///
order($iv $cv $jobs $exp $wel _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear


**** TABLE A4 ****

global fix2 "i.ccode"
global disaster "L.s_earth L.s_vol L.s_storm"

$method ln_socialinfra $fix2 $iv $cv $disaster , het
$method ln_economicinfra $fix2 $iv $cv $disaster , het
$method ln_humanaid $fix2 $iv $cv $disaster , het

esttab, nogap comp se(3) b(3) keep($iv $cv $disaster _cons) ///
order($iv $cv $disaster _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear
	 

**** TABLE A5 ****

$method ln_social_infra_human $fix $iv $cv , het
$method ln_econ_infra_human $fix $iv $cv , het

esttab, nogap comp se(3) b(3) keep($iv $cv _cons) ///
order($iv $cv _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear
	 

**** TABLE A6 ****

global method "eststo: xtpcse"
global dv "ln_aid"
global fix "i.ccode i.year"
global iv "L.f_economic_hardship"
global int "L.log_rile cL.f_economic_hardship#cL.log_rile"
global int2 "L.log_internationalism cL.f_economic_hardship#cL.log_internationalism"
global cv2 "L.ln_gdppc L.wdi_gdpgr L.wdi_trade L.College L.studyabroad L.female L.age"

$method $dv $fix $iv $int $cv2 , het
$method $dv $fix $iv $int2 $cv2 , het

esttab, nogap comp se(3) b(3) keep($iv $int $int2 $cv2 _cons) ///
order($iv $int $int2 $cv2 _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear


**** TABLE A7 ****

global method "eststo: xtpcse"
global dv "ln_aid"
global fix "i.ccode i.year"
global iv "L.f_economic_hardship"
global int "L.log_rile cL.f_economic_hardship#cL.log_rile"
global cv "L.ln_gdppc L.wdi_gdpgr L.wdi_trade L.log_rile L.College L.studyabroad L.female L.age"

$method $dv $fix $iv $cv if L.presidentialism==0, het
$method $dv $fix $iv $cv if L.presidentialism==1, het

esttab, nogap comp se(3) b(3) keep($iv $cv _cons) ///
order($iv $cv _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear


**** TABLE A8 ****

global method "eststo: xtpcse"
global dv "ln_aid"
global fix "i.ccode i.year"
global iv "L.f_economic_hardship"
global int "L.diff_RILE cL.f_economic_hardship#cL.diff_RILE"
global int2 "L.m_independent cL.f_economic_hardship#cL.m_independent"
global cv "L.ln_gdppc L.wdi_gdpgr L.wdi_trade L.log_rile L.College L.studyabroad L.female L.age"

$method $dv $fix $iv $int $cv , het
$method $dv $fix $iv $int2 $cv , het

esttab, nogap comp se(3) b(3) keep($iv $int $int2 $cv _cons) ///
order($iv $int $int2 $cv _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear
	 

**** TABLE A9 ****

global method "eststo: xtpcse"
global dv "ln_aid"
global fix "i.ccode i.year"
global iv "L.f_economic_hardship"
global int "L.businessman cL.f_economic_hardship#cL.businessman"
global cv "L.ln_gdppc L.wdi_gdpgr L.wdi_trade L.log_rile L.College L.studyabroad L.female L.age"

$method $dv $fix $iv $int , het
$method $dv $fix $iv $int $cv , het

esttab, nogap comp se(3) b(3) keep($iv $int $cv _cons) ///
order($iv $int $cv _cons) r2 star(* 0.10 ** 0.05 *** 0.01) 
eststo clear

	 
	 
**** Figure A1 *****

twoway line total_aid year if ccode==900 & year>=1975, scheme(s2mono) ///
ytitle("Foreign Aid (2018 constant USD, in millions)") xtitle(year) name(FigureA1, replace)





